<?php

/**
 * avatar actions.
 *
 * @package    testdev
 * @subpackage avatar
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class avatarActions extends sfActions
{
	
	public function executeSave(sfWebRequest $request) {
		$avatar = $this->getUser()->getGuardUser()->getAvatar();
		$id = $request->getParameter('id');
		$image = $request->getPostParameter("image");
		
		$avatar->setImage($image);
		$avatar->save();
	
	}
	
  public function executeShow(sfWebRequest $request) {
  	$paramTailleAvatar = Doctrine_Core::getTable('TestdevParamTailleAvatar')->find(1);
  	
  	$this->getUser()->setAttribute('taille_avatar_x',     $paramTailleAvatar->getTaille_avatar_x());
    $this->getUser()->setAttribute('taille_avatar_y',     $paramTailleAvatar->getTaille_avatar_y());
    
  	$avatar = $this->getUser()->getGuardUser()->getAvatar();
  	 
  	$this->testdev_avatar = Doctrine_Core::getTable('TestdevAvatar')->find($avatar->getId());
  	$this->forward404Unless($this->testdev_avatar);
  
    //$this->testdev_avatar = Doctrine_Core::getTable('TestdevAvatar')->find(array($request->getParameter('id')));
    //$this->forward404Unless($this->testdev_avatar);
  }
  

  /*

  public function executeIndex(sfWebRequest $request)
  {
    $avatar = $this->getUser()->getGuardUser()->getAvatar();
  	$this->redirect('avatar/show?id='.$avatar->getId());
  	//$this->form = new TestdevAvatarForm($testdev_avatar);
  	
  	
    //$this->testdev_avatars = Doctrine_Core::getTable('TestdevAvatar')
    //  ->createQuery('a')
    //  ->execute();
    
  }


  public function executeNew(sfWebRequest $request)
  {
    $this->form = new TestdevAvatarForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new TestdevAvatarForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($testdev_avatar = Doctrine_Core::getTable('TestdevAvatar')->find(array($request->getParameter('id'))), sprintf('Object testdev_avatar does not exist (%s).', $request->getParameter('id')));
    $this->form = new TestdevAvatarForm($testdev_avatar);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($testdev_avatar = Doctrine_Core::getTable('TestdevAvatar')->find(array($request->getParameter('id'))), sprintf('Object testdev_avatar does not exist (%s).', $request->getParameter('id')));
    $this->form = new TestdevAvatarForm($testdev_avatar);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($testdev_avatar = Doctrine_Core::getTable('TestdevAvatar')->find(array($request->getParameter('id'))), sprintf('Object testdev_avatar does not exist (%s).', $request->getParameter('id')));
    $testdev_avatar->delete();

    $this->redirect('avatar/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $testdev_avatar = $form->save();

      $this->redirect('avatar/edit?id='.$testdev_avatar->getId());
    }
  }
  */
}
